package org.thunms.framework.utils;

import java.beans.PropertyEditorSupport;

import org.apache.commons.lang.StringUtils;


public class CustomBooleanEditor  extends PropertyEditorSupport {

	@Override
	public String getAsText() {
		return String.valueOf(this.getValue());
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		//主要解决前台没有传值的情况下如何处理
		if (StringUtils.isBlank(text)) {// 解决前台传过来null的BUG
			setValue(null);
		} else if ("1".equals(text.trim())) {//0 is true
			setValue(true);
		}else if("0".equals(text.trim())){
			setValue(false);
		} else {
			this.setValue(Boolean.parseBoolean(text));
		}
		
	}

}
